<template>
  <div class="app-container" >
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" @click.left.native="close">
      <el-form-item label="小区" prop="areaName">
        <el-select v-model="queryParams.areaName":filter-method="filterMethod" placeholder="请输入小区" filterable allow-create
                   clearable size="small" @change="getGroup(queryParams.areaName)" default-first-option>
          <el-option v-for="(item, index) in areaIdOptions" :key="index" :label="item.areaName"
                     :value="item.areaName" :disabled="item.disabled" ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="楼宇" prop="groupName">
        <el-select v-model="queryParams.groupName" placeholder="请输入楼宇" clearable size="small" @change="getUnit(queryParams.areaName,queryParams.groupName)">
          <el-option v-for="(item, index) in groupIdOptions" :key="index" :label="item.groupName"
                     :value="item.groupName" :disabled="item.disabled" ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="单元" prop="unitName">
        <el-select v-model="queryParams.unitName" placeholder="请输入楼宇" clearable size="small" >
          <el-option v-for="(item, index) in unitNameOptions" :key="index" :label="item.unitName"
                     :value="item.unitName" :disabled="item.disabled" ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="户" prop="doorName">
        <el-input
          v-model="queryParams.doorName"
          placeholder="请输入户"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房屋编号" prop="houseId">
        <el-input
          v-model="queryParams.houseId"
          placeholder="请输入房屋编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-upload"
          size="mini"
          @click="handleImport"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-upload"
          size="mini"
          @click="weChatPay"
        >微信扫码支付</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :cell-style="tableRowClassName" v-loading="loading" :data="doorList" @selection-change="handleSelectionChange" @cell-contextmenu="preventSelect" @contextmenu.prevent.native="openMenu($event)" @click.left.native="close" >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="小区" align="center" prop="areaName" />
      <el-table-column label="楼宇" align="center" prop="groupName" />
      <el-table-column label="单元" align="center" prop="unitName" />
      <el-table-column label="户" align="center" prop="doorName" />
      <el-table-column label="应缴金额" align="center" prop="budgetMoney" />
      <el-table-column label="已缴金额" align="center" prop="costMoney" />
      <el-table-column label="本金余额" align="center" prop="balance" />
      <el-table-column label="面积" align="center" prop="space" />
      <el-table-column label="房屋用途" align="center" prop="purposeName" />
      <el-table-column label="房屋编号" align="center" prop="houseId" />
      <el-table-column label="姓名" align="center" prop="userName" />
      <el-table-column label="电话" align="center" prop="tel" />
      <el-table-column label="证件号码" align="center" prop="papersCode" />
      <el-table-column label="实测状态" align="center" prop="spaceSts">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.HOUSE002" :value="scope.row.spaceSts"/>
        </template>
      </el-table-column>
      <el-table-column label="最后缴费时间" align="center" prop="costDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.costDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="缴费状态" align="center" prop="costSts">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.HOUSE003" :value="scope.row.costSts"/>
        </template>
      </el-table-column>
      <el-table-column label="计息方式" align="center" prop="rateType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.HOUSE004" :value="scope.row.rateType"/>
        </template>
      </el-table-column>
      <el-table-column label="利息合计" align="center" prop="rateMoney" />
      <el-table-column label="计息时间" align="center" prop="rateDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rateDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建者" align="center" prop="creater" />
      <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center"  fixed="right"  class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            :style="{ display: scope.row.areaName=='合计'?'none':'' }"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            :style="{ display: scope.row.areaName=='合计'?'none':'' }"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <ul v-show="visible" :style="{left:left+'px',top:top+'px'}" class="contextmenu">
      <li @click="costQuery"> 缴费记录 </li>
      <li @click="rateQuery"> 计息明细</li>
    </ul>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改户管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="小区" prop="areaName">
              <el-select v-model="form.areaName":filter-method="filterMethod" placeholder="请输入小区" filterable allow-create
                         clearable size="small" @change="getGroup(form.areaName)" default-first-option >
                <el-option v-for="(item, index) in areaIdOptions" :key="index" :label="item.areaName"
                           :value="item.areaName" :disabled="item.disabled" ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="楼宇" prop="groupName">
              <el-select v-model="form.groupName" placeholder="请输入楼宇" clearable :style="{width: '100%'}" @change="getUnit(form.areaName,form.groupName)" >
                <el-option v-for="(item, index) in groupIdOptions" :key="index" :label="item.groupName"
                           :value="item.groupName" :disabled="item.disabled" ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="单元" prop="unitName">
              <el-select v-model="form.unitName" placeholder="请输入单元" clearable :style="{width: '100%'}" >
                <el-option v-for="(item, index) in unitNameOptions" :key="index" :label="item.unitName"
                           :value="item.unitName" :disabled="item.disabled" ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="户" prop="doorName">
              <el-input v-model="form.doorName" placeholder="请输入户"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="面积" prop="space" >
              <el-input  v-model="form.space" placeholder="请输入面积"  @input="paymentChanges()" :disabled="noWrite"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
          </el-col>
          <el-col :span="12">
            <el-form-item label="应缴金额" prop="budgetMoney" >
              <el-input  v-model="form.budgetMoney" placeholder="应缴金额" :disabled="noWrite"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="用途" prop="purposeName">
              <el-select v-model="form.purposeName" @change="paymentChanges" placeholder="请输入用途" clearable :style="{width: '100%'}" :disabled="noWrite">
                <el-option v-for="(item, index) in purposeOptions" :key="index" :label="item.purposeName" @change="paymentChanges"
                           :value="item.purposeName" :disabled="item.disabled" ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="姓名" prop="userName">
              <el-input v-model="form.userName" placeholder="请输入姓名" :disabled="noWrite"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="电话" prop="tel">
              <el-input v-model="form.tel" placeholder="请输入电话" :disabled="noWrite"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证件号码" prop="papersCode">
              <el-input v-model="form.papersCode" placeholder="请输入证件号码" :disabled="noWrite"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-col :span="12">
          <el-form-item label="房款" prop="houseMoney">
            <el-input v-model="form.houseMoney" @change="paymentChanges" placeholder="请输入房款信息" :disabled="noWrite"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button type="primary" @click="resetQuery">重置</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="titleDoorExecute" :visible.sync="openDoor" append-to-body width="500px">
      <el-form ref="form" :model="formDoor" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="小区" prop="areaName">
              <el-select v-model="formDoor.areaName":filter-method="filterMethod" placeholder="请输入小区" filterable allow-create
                         clearable size="small" @change="getGroup(form.areaName)" default-first-option>
                <el-option v-for="(item, index) in areaIdOptions" :key="index" :label="item.areaName"
                           :value="item.areaName" :disabled="item.disabled" ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="楼宇" prop="groupName">
              <el-select v-model="formDoor.groupName" placeholder="请输入楼宇" clearable :style="{width: '100%'}" @change="getUnit(form.areaName,form.groupName)">
                <el-option v-for="(item, index) in groupIdOptions" :key="index" :label="item.groupName"
                           :value="item.groupName" :disabled="item.disabled" ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="单元" prop="unitName">
              <el-select v-model="formDoor.unitName" placeholder="请输入单元" clearable :style="{width: '100%'}" >
                <el-option v-for="(item, index) in unitNameOptions" :key="index" :label="item.unitName"
                           :value="item.unitName" :disabled="item.disabled" ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="户" prop="doorName">
              <el-input v-model="formDoor.doorName" placeholder="请输入户" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitDoorForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看缴费记录 -->
    <el-dialog :title="title" :visible.sync="openCost" width="1000px" append-to-body>
      <el-form :model="queryParams1" :inline="true" v-show="showSearch" label-width="68px">
        <el-table v-loading="loading" :data="costQueryList">
          <el-table-column label="缴费编号" align="center" prop="costId" />
          <el-table-column label="房屋编号" align="center" prop="houseId" />
          <el-table-column label="流水号" align="center" prop="serial" />
          <el-table-column label="缴费金额" align="center" prop="costMoney" />
          <el-table-column label="缴费时间" align="center" prop="costDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.costDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="缴费状态" align="center" prop="costSts">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.COST001" :value="scope.row.costSts"/>
            </template>
          </el-table-column>
          <el-table-column label="缴费渠道" align="center" prop="costWay">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.COST002" :value="scope.row.costWay"/>
            </template>
          </el-table-column>
          <el-table-column label="对账状态" align="center" prop="checkSts">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.COST003" :value="scope.row.checkSts"/>
            </template>
          </el-table-column>
          <el-table-column label="发票号码" align="center" prop="billNo" />
          <el-table-column label="收费员" align="center" prop="creater" />
          <el-table-column label="创建时间" align="center" prop="createDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备注" align="center" prop="remark" />
        </el-table>
        <pagination
          v-show="total>0"
          :total="total1"
          :page.sync="queryParams1.pageNum"
          :limit.sync="queryParams1.pageSize"
          @pagination="getCostList"
        />
      </el-form>
    </el-dialog>

    <!-- 查看计息明细记录 -->
    <el-dialog :title="title" :visible.sync="openRate" width="1000px" append-to-body>
      <el-form :model="queryParams2" :inline="true" v-show="showSearch" label-width="68px">
        <el-table v-loading="loading" :data="rateQueryList">
          <el-table-column label="房屋编号" align="center" prop="houseId" width="333"/>
          <el-table-column label="利息合计" align="center" prop="rateMoney" width="333"/>
          <el-table-column label="计息日" align="center" prop="rateDate" width="334">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.rateDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total2"
          :page.sync="queryParams2.pageNum"
          :limit.sync="queryParams2.pageSize"
          @pagination="getRateList"
        />
      </el-form>
    </el-dialog>
    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px">
      <el-select v-model="upload.areaName" placeholder="请输入小区" clearable :style="{width: '100%'}" >
        <el-option v-for="(item, index) in areaIdOptions" :key="index" :label="item.areaName"
                   :value="item.areaName" :disabled="item.disabled" ></el-option>
      </el-select>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport + '&areaName='+upload.areaName"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
          <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="cancelFileForm">取 消</el-button>

      </div>
    </el-dialog>



  </div>
</template>

<script>
import {
  listDoor,
  weChatPay,
  getDoor,
  delDoor,
  addDoor,
  updateDoor,
  updateDoorName,
  getAreaInfo,
  getAreaInfo1,
  getGroupInfo,
  getUnitInfo,
  getPurposeInfo,
  listRateQuery,
  getDoorAddr
} from "@/api/house/door";
import { listCostQuery } from "@/api/fund/costQuery";
import { getToken } from "@/utils/auth";


export default {

  name: "Door",
  dicts: ['HOUSE003', 'HOUSE004','HOUSE002','HOUSE018','HOUSE019'],
  data() {
    return {
      visible: false,
      left: 0,
      top: 0,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      noWrite: false,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total1: 0,
      total2: 0,
      // 户管理表格数据
      doorList: [],
      costQueryList: [],
      rateQueryList: [],
      // 弹出层标题
      title: "",
      titleDoorExecute: "",
      // 是否显示弹出层
      open: false,
      openCost: false,
      openRate: false,
      openDoor: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        areaName: null,
        groupName: null,
        unitName: null,
        doorName: null,
        houseId: null,
        purposeId: null,
        userName: null,
      },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/house/door/importData"
      },
      // 查询缴费参数
      queryParams1: {
        pageNum: 1,
        pageSize: 10,
        houseId: null,
        costDate: null,
        costSts: null,
        costWay: null,
        checkSts: null,
        billNo: null,
      },
      // 查询计息参数
      queryParams2: {
        pageNum: 1,
        pageSize: 10,
        houseId: null,
        rateMoney: null,
        rateDate: null
      },
      areaIdOptions:[{}],
      groupIdOptions:[{}],
      unitNameOptions:[{}],
      purposeOptions:[{}],
      // 表单参数
      form: {},
      formDoor: {},
      // 表单校验
      rules: {
        areaName: [
          { required: true, message: "小区不能为空", trigger: "change" }
        ],
        groupName: [
          { required: true, message: "楼宇不能为空", trigger: "change" }
        ],
        unitName: [
          { required: true, message: "单元不能为空", trigger: "change" }
        ],
        doorName: [
          { required: true, message: "户不能为空", trigger: "blur" }
        ],
        purposeName: [
          { required: true, message: "用途不能为空", trigger: "blur" }
        ],
        space: [
          { required: true, message: "面积不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.areaSelect();
    this.filterMethod();
    this.purposeSelect();
  },
  methods: {
    //扫码支付
    weChatPay(row) {
      debugger
      this.reset();
      const doorId = this.doorId
      return weChatPay(doorId).then(response => {
        let baseUrl = "http://" + response.data.addr;
        window.open(baseUrl);
      });
    },
    filterMethod(val){
      this.value=val
      getAreaInfo1(this.value).then(response => {
        this.areaIdOptions = response.rows;
      });
    },
    /** 执行按钮操作 */
    submitDoorForm() {
      updateDoorName(this.ids, this.formDoor).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.openDoor = false;
        this.getList();
      });
    },
    paymentChanges(){
      debugger
      var _this = this;
      var data1 = _this.form.space;
      var data2 = _this.form.purposeName;
        let budgetMoney = data1* data2;
        this.form.budgetMoney=budgetMoney.toFixed(0)
        return this.form.budgetMoney

    },
    tableRowClassName({row}){
      return row.balance/row.budgetMoney>'0.3'?'color: black;':(row.balance/row.budgetMoney<0.3?'color: red;':"")
    },
    areaSelect(){
      getAreaInfo().then(response => {
        this.areaIdOptions = response.rows;
      });
    },
    getGroup(areaName){
      if(areaName!=""){
        getGroupInfo(areaName).then(response => {
          this.groupIdOptions = response.rows;
        });
      }
    },
    getUnit(areaName,groupName){
      getUnitInfo(areaName,groupName).then(response => {
        this.unitNameOptions = response.rows;
      });
    },
    purposeSelect(){
      getPurposeInfo().then(response => {
        this.purposeOptions = response.rows;
      });
    },
    /** 查询户管理列表 */
    getList() {
      this.loading = true;
      listDoor(this.queryParams).then(response => {
        this.doorList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询缴费信息列表 */
    getCostList() {
      this.loading = true;
      listCostQuery(this.queryParams1).then(response => {
        this.costQueryList = response.rows;
        this.total1 = response.total;
        this.loading = false;
      });
    },
    /** 查询计息明细列表 */
    getRateList() {
      this.loading = true;
      listRateQuery(this.queryParams2).then(response => {
        this.costRateList = response.rows;
        this.total2 = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openDoor = false;
      this.openCost = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        doorId: null,
        houseMoney: null,
        areaName: null,
        groupName: null,
        unitName: null,
        doorName: null,
        houseId: null,
        space: null,
        purposeName: null,
        spaceSts: null,
        purposeId: null,
        userName: null,
        tel: null,
        papersCode: null,
        budgetMoney: null,
        purposeMoney: null,
        buildMoney: null,
        costMoney: null,
        costDate: null,
        costSts: null,
        balance: null,
        rateType: null,
        rateMoney: null,
        rateDate: null,
        creater: null,
        createDate: null,
        remark: null
      };
      this.formDoor = {
        areaName: null,
        groupName: null,
        unitName: null,
        doorName: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.areaSelect();
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.areaSelect();
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.doorId)
      this.doorId = selection.map(item => item.doorId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    preventSelect(selection) {
      this.houseId = selection.houseId
    },

    openMenu(e) {
      this.reset();
      const menuMinWidth = 105
      const offsetLeft = this.$el.getBoundingClientRect().left // container margin left
      const offsetWidth = this.$el.offsetWidth // container width
      const maxLeft = offsetWidth - menuMinWidth // left boundary
      const left = e.clientX - offsetLeft + 15 // 15: margin right
      if (left > maxLeft) {
        this.left = maxLeft
      } else {
        this.left = left
      }
      this.top = e.clientY-80
      this.visible = true
    },
    close() {
      this.reset();
      this.visible = false
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const doorId = row.doorId || this.ids
      getDoor(doorId).then(response => {
        this.noWrite = true;
        this.form = response.data;
        this.open = true;
        this.title = "户迁移";
      });
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      debugger
      this.reset();
      const doorId = row.doorId || this.ids
      if(doorId.length>0) {
        if(doorId.length==1) {
          getDoorAddr(doorId).then(response => {
            this.noWrite = false;
            this.form = response.data;
            this.open = true;
            this.title = "添加户管理";
          });}else{
          return this.$modal.alertError("想户复制请勾选一个复选框");
        }
      }else {
        this.noWrite = false;
        this.reset();
        this.areaSelect();
        this.open = true;
        this.title = "添加户管理";
      }
    },
    /** 修改按钮操作 */
    handleUpdateDoor(row) {
      this.reset();
      const doorId = row.doorId || this.ids
      getDoor(doorId).then(response => {
        this.formDoor = response.data;
        this.openDoor = true;
        this.titleDoor = "户迁移";
      });
    },
    /** 获取缴费记录 */
    costQuery() {
      this.reset();
      const houseId = this.houseId
      this.queryParams1.houseId=houseId
      this.visible = false
      this.openCost = true;
      this.getCostList()
    },
    /** 获取计息记录 */
    rateQuery() {
      this.reset();
      const houseId = this.houseId
      this.queryParams2.houseId=houseId
      this.visible = false
      this.openRate = true;
      this.getRateList()
    },
    /** 提交按钮 */
    submitForm() {
      debugger
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.doorId != null) {
            updateDoor(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDoor(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.areaSelect();
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const doorIds = row.doorId || this.ids;
      this.$modal.confirm('是否确认删除户管理编号为"' + doorIds + '"的数据项？').then(function() {
        return delDoor(doorIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('house/door/export', {
        ...this.queryParams
      }, `door_${new Date().getTime()}.xlsx`)
    },


    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    cancelFileForm() {
      this.upload.open = false;
      this.upload.areaName = null;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('door/importTemplate', {
      }, `user_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
      this.upload.areaName = null;
    }

  }
};
</script>



<style lang="scss" scoped>

.contextmenu {
  margin: 0;
  background: #fff;
  z-index: 3000;
  position: absolute;
  list-style-type: none;
  padding: 5px 0;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 400;
  color: #333;
  box-shadow: 2px 2px 3px 0 rgba(0, 0, 0, .3);
  li {
    margin: 0;
    padding: 7px 16px;
    cursor: pointer;
    &:hover {
      background: #eee;
    }
  }
}

</style>

<style lang="scss">
//reset element css of el-icon-close
.tags-view-wrapper {
  .tags-view-item {
    .el-icon-close {
      width: 16px;
      height: 16px;
      vertical-align: 2px;
      border-radius: 50%;
      text-align: center;
      transition: all .3s cubic-bezier(.645, .045, .355, 1);
      transform-origin: 100% 50%;
      &:before {
        transform: scale(.6);
        display: inline-block;
        vertical-align: -3px;
      }
      &:hover {
        background-color: #b4bccc;
        color: #fff;
      }
    }
  }
}


</style>
